#!/bin/sh
#
# estbwrm
#	remove an estbw printer description
#
#	Usage: estbwrm <queue name>
#
# Copyright (c) 2017, Toshiba (Australia) Pty. Limited
# All rights reserved.
#
# Version 7.90		2017/10/19
#

if [ $# -ne 1 ]
then
	echo "Usage: $0 <queue name>"
	exit 1
fi

osType=`uname -s`

if [ $osType = "AIX" ]
then
	echo "Doing ESTBW removal for $1 on AIX"

	printer="$1"
	device="dev_"$1

	rm /opt/toshiba/tap/filter/$printer
	rm /opt/toshiba/tap/filter/$printer.conf
	rmquedev -q$printer -d$device
	rmque -q$printer
elif [ $osType = "SCO_SV" ]
then
	echo "Doing ESTBW removal for $1 on SCO_SV"

	/usr/lib/lpadmin -x $1

	printer_conf=/usr/spool/lp/admins/lp/interfaces/$1.conf

	if [ -f "${printer_conf}" ]
	then
		rm ${printer_conf}
	fi
elif [ $osType = "SunOS" ]
then
	echo "Doing ESTBW removal for $1 on SunOS"

	lpadmin -x $1
	
	osVersion="$(uname -v)"
	if [ "$((${osVersion}>=11.2))" = "1" ]
	then
		printer_conf=/etc/cups/interfaces/$1.conf
	else
		printer_conf=/etc/lp/interfaces/$1.conf
	fi

	if [ -f "${printer_conf}" ]
	then
		rm ${printer_conf}
	fi
elif [ $osType = "HP-UX" ]
then
	echo "Doing ESTBW removal for $1 on HP-UX"

	#
	# check if the schedule is running and if it
	# is we have to stop it and then restart it.
	#
	ps -ef | grep lpsched | grep -iv grep > /dev/null 2>&1
	nosched=$?

	if [ $nosched = 0 ]
	then
		/usr/sbin/lpshut > /dev/null 2>&1
	fi

	/usr/sbin/lpadmin -x$1		# delete the printer

	printer_conf=/etc/lp/interface/$1.conf

	if [ -f "${printer_conf}" ]
	then
		rm ${printer_conf}
	fi

	#
	# If it was running then start it again
	#
	if [ $nosched = 0 ]
	then
		/usr/sbin/lpsched > /dev/null 2>&1
	fi
elif [ $osType = "Linux" ]
then
	echo "Doing ESTBW removal for $1 on Linux"

	printer="$1"

#
#	Remove the filter and config file then remove the
#	entry from the printcap file
#
	rm /opt/toshiba/tap/interface/$printer
	rm /opt/toshiba/tap/interface/$printer.conf
	/opt/toshiba/tap/bin/modPrintcap -d $printer
	if [ -f /opt/toshiba/tap/bin/flag_$printer ]
	then
		/opt/toshiba/tap/bin/printconf_import -d $printer
		rm /opt/toshiba/tap/bin/flag_$printer
	fi
	echo "Please restart lpd !"
else
	echo "Doing ESTBW removal for $1 on Caldera OpenUNIX Default ?"

	lpadmin -x $1

	printer_conf=/etc/lp/interfaces/$1.conf

	if [ -f "${printer_conf}" ]
	then
		rm ${printer_conf}
	fi
fi

